function getStartNumberAndEndNumber(pageNumber, pageTotalCount, continues) {
    check(pageNumber, pageTotalCount, continues);
    // printParam(pageNumber, pageTotalCount, continues);
    continues--;
    let startNumber = pageNumber;
    let endNumber = pageNumber;
    if (pageTotalCount <= continues) {
        endNumber = pageTotalCount;
        return printPagination(pageNumber, startNumber, endNumber);
        return;
    }
    let index = 1;
    while (continues > 0) {
        if (pageNumber + (-index) >= 1 && pageNumber + (+index) <= pageTotalCount && continues >= 2) {
            startNumber--;
            endNumber++;
            index++;
            continues -= 2;
            continue;
        }
        if (pageNumber + (-index) >= 1) {
            startNumber--;
            continues--;
        } else if (pageNumber + (+index) <= pageTotalCount) {
            endNumber++;
            continues--;
        }
        index++;
    }
    return printPagination(pageNumber, startNumber, endNumber);
}

export {getStartNumberAndEndNumber};

/**
 * 打印分页器
 */
function printPagination(pageNumber, start, end) {
    let array=[];
    for (let i = start; i <= end; i++) {
        array.push(i);
    }
    let s="";
    for (let i = 0; i < array.length; i++) {
        if(array[i]===pageNumber){
            s+=` <${array[i]}> `;
        }else {
            s+=` ${array[i]} `;
        }
    }
    return array;
}

/**
 * 校验参数
 */
function check(pageNumber, pageTotalCount, continues) {
    if (pageNumber < 1) {
        throw Error('分页异常：当前页码必须大于0')
    }
    if (pageNumber > pageTotalCount) {
        throw Error('分页异常：当前页码比总页数大');
    }
}

/**
 * 打印参数
 */
function printParam(pageNumber, pageTotalCount, continues) {
    console.log(`pageNumber: ${pageNumber}`)
    console.log(`pageTotalCount: ${pageTotalCount}`)
    console.log(`continues: ${continues}`)
}